<template>
	<view class="index f16 b89d" v-if="form.id" @click="outShow = false">
		<u-navbar class="nav" title=" " leftIconColor="#000" leftIconSize="24px" :bgColor="subColor"
			titleStyle="color:#000;font-size:36rpx;" :placeholder="true" safeAreaInsetTop :autoBack="true">
		</u-navbar>
		<view class="tac f20 pt15 top pb80 c0" :style="{background:subColor}">
			{{ form.status_name }}
			<view class="f12 mt5">抖音</view>
		</view>
		<view class="page p10" style="position:relative;top:-50px">
			<view class="card mb10" style="font-size:29rpx;">
				<view class="p10 bs6">
					<view class="f-c-c">
						<view class="f14 c6">{{'取单号'}}</view>
						<view class="f30 wei mt10">
							<text>{{form.pick_up_code}}</text>
							<text class="ml5 f10 bs4"
								:style="{padding: '8rpx',background: subColor,color: '#000'}">点单</text>
							<!-- <text class="ml5 f10 bs4" :style="{padding: '8rpx',background: '#FDDA34',color: '#000'}"
								v-if="form.appointment == 1">预</text>
							<text class="ml5 f10 bs4" :style="{padding: '8rpx',background: subColor,color: '#000'}"
								v-if="form.scene==2 && form.diningType == 1">打包</text> -->
						</view>
					</view>
				</view>
			</view>
			<!-- <view class="flex bz mt10 bs4 f-y-t" v-if="form.notes">
				<view class="left f10 bs4 mr5 f-g-0">备注</view>
				<view class="f14 wei">{{ form.notes}}</view>
			</view> -->
			<view class="card mt10">
				<view class="dfbc">
					<view class="c0 wei6 mb10">商品<text
							class="f12 nowei ml5">{{form.sku && form.sku.length}}种共{{form.sku.length}}件</text></view>
					<!-- <view class="button_color" :style="{color:subColor,border:'1px solid'+subColor}" @click="torefund"
						v-if="form.state > 2 && form.state < 7">退款/取消</view> -->
				</view>
				<view class="f-bt p-10-0 f12" v-for="(item,index) in form.sku" :key="index">
					<view class="f-g-1">
						<view class="flex f-y-c">
							<image class="mr10 f-g-0 bs5" v-if="item.product_info.img"
								style="width: 60rpx;height: 60rpx" :src="item.product_info.img" mode="aspectFill"
								@click="onPreviewTap(item.product_info.img)"></image>
							<view class="c0 t-o-e l-h1 f13">{{item.product_info.name}}</view>
						</view>
						<view class="c9 mt5 flex">
							<view>
								规格：
							</view>
							<view>
								<view v-for="(vvv, ii) in item.sku_name_info" :key="ii">
									<view>
										<text>{{vvv.class_name}}：</text>
										<text>{{vvv.sku_name.name}}</text>
									</view>
								</view>
							</view>
						</view>
						<!-- 						<view v-if="item.attrData.attr" class="c9 mt5">属性：{{item.attrData.attr}}</view> -->
						<view class="c9 mt5 flex" v-if="item.add_info.length>0">
							<view>
								加料：
							</view>
							<view class="flex">
								<view v-for="(vvv, ii) in item.add_info" :key="ii">
									<view>
										<text>{{vvv.name}}；</text>
									</view>
								</view>
							</view>
						</view>
						<!-- <view v-if="item.setMealData && item.setMealData.length" class="c9 mt5">
							<view v-for="(cv,ci) in item.setMealData" :key="ci">{{cv.name}}*{{cv.num}}
								<text v-if="cv.attrData && cv.attrData.attr"
									class="ml10">[{{ cv.attrData.attr }}]</text>
								<text v-if="cv.attrData && cv.attrData.matal"
									class="ml10">[{{ cv.attrData.matal }}]</text>
							</view>
						</view> -->
					</view>
					<!-- <view class="f-g-0 c9 mr15 mumber f-y-c">x{{item.num}}</view>
					<view class="f-g-0 mumber f-y-c">￥{{item.money}}</view> -->
				</view>
				<view class="f-bt mt10 c0" v-if="form.boxMoney>0">
					<view class="f12">包装费</view>
					<view class="f12">￥{{form.boxMoney}}</view>
				</view>
				<view class="f-bt c0 mt10" v-if="form.scene==1 && form.payDeliveryMoney>0">
					<view class="f12">配送费</view>
					<view class="f12">￥{{form.payDeliveryMoney}}</view>
				</view>
				<view class="f-bt c0 mt10" v-if="form.discountMoney>0">
					<view class="f12">总优惠</view>
					<view class="f12 flex f-y-c p-r">￥{{form.discountMoney}}
						<!-- <view class="ml5"><u-icon size="12" color="#666" name="arrow-right" style="line-height: 26rpx;"></u-icon></view> -->
					</view>
				</view>
				<view class="f-x-e f14 mt5 bt1 pt10 mt10">
					<view class="f12">
						<text>小计</text>
						<text class="cf5f">￥</text>
						<text class="f18 cf5f wei6">{{form.origin_amount/100}}</text>
					</view>
				</view>
			</view>
			<!-- 			<view class="card mt10 f12" style="font-size:30rpx;color:#999"
				v-if="form.discounts && (form.discounts.fullsub || form.discounts.newSub || form.discounts.coupon || form.discounts.deliveryCoupon)">
				<view class="mb10 wei6 c0 ">优惠信息</view>
				<view class="dfbc mb10 f12" v-if="form.discounts && form.discounts.fullsub">
					<text>满减</text>
					<text class="cf5f">-￥{{ form.discounts.fullsub.money }}</text>
				</view>
				<view class="dfbc mb10 f12" v-if="form.discounts && form.discounts.newSub">
					<text>新客立减</text>
					<text class="cf5f">-￥{{ form.discounts.newSub.money }}</text>
				</view>
				<view class="dfbc mb10 f12" v-if="form.discounts && form.discounts.coupon">
					<text>优惠券</text>
					<text class="cf5f">-￥{{ form.discounts.coupon.money }}</text>
				</view>
				<view class="dfbc mb10 f12" v-if="form.discounts && form.discounts.deliveryCoupon">
					<text>配送券</text>
					<text class="cf5f">-￥{{ form.discounts.deliveryCoupon.money }}</text>
				</view>
				<view class="dfbc mb10 f12">
					<text>优惠合计</text>
					<text>￥{{form.discountMoney || 0}}</text>
				</view>
			</view> -->
			<view class="card mt10 f12" style="font-size:30rpx;color:#999">
				<view class="f-bt">
					<view class="mb10 wei6 c0">支付信息</view>
					<view class="f12 cf5f" v-if="form.status>=20">已支付</view>
				</view>
				<view class="dfbc p-5-0 f12 c0">
					<text>用户实付</text>
					<text>￥{{ form.origin_amount/100 }}</text>
				</view>
				<view class="dfbc p-5-0 f12 c0">
					<text>支付方式</text>
					<text>支付</text>
				</view>
				<view class="dfbc p-5-0 f12 c0">
					<text>本单预计收入</text>
					<text>￥{{ form.origin_amount/100 }}</text>
				</view>
			</view>
			<view class="card mt10 f12" style="font-size:30rpx;color:#999" v-if="form.refund != null">
				<view class="f-bt">
					<view class="mb10 wei6 c0">退款信息</view>
					<view class="f12 cf5f">已退款</view>
				</view>
				<view class="dfbc p-5-0 f12 c0">
					<text>退款单号</text>
					<text>{{ form.refund.refund_no}}</text>
				</view>
				<view class="dfbc p-5-0 f12 c0">
					<text>退款金额</text>
					<text>￥{{ form.refund.refund_amount/100 }}</text>
				</view>
				<view class="dfbc p-5-0 f12 c0">
					<text>用户退款金额</text>
					<text>￥{{ form.refund.user_refund_amount/100 }}</text>
				</view>
				<view class="dfbc p-5-0 f12 c0">
					<text>退款单时间</text>
					<text>{{ form.refund.return_time }}</text>
				</view>
				<view class="dfbc p-5-0 f12 c0" v-if="form.refund.refund_reason">
					<text>退款原因</text>
					<text>{{ form.refund.refund_reason }}</text>
				</view>
			</view>
			<!-- <view class="card mt10" style="font-size:30rpx;color:#999"
				v-if="form.scene == 1 && form.state==5 && form.deliveryOrder">
				<view class="mb10 wei6 c0">配送信息</view>
				<view class="dfbc mb10 f12">
					<text class="">配送平台</text>
					<text class="c0">{{form.deliveryOrder.deliveryTypeFormat}}</text>
				</view>
				<view class="dfbc mb10 f12">
					<text class="">配送渠道</text>
					<text class="c0">{{form.deliveryOrder.channelName}}</text>
				</view>
				<view class="dfbc f12 mb10" v-if="form.deliveryOrder && form.deliveryOrder.rider">
					<view class="">配送骑手</view>
					<view class="c0 flex">
						{{form.deliveryOrder.rider && form.deliveryOrder.rider.name}}
						{{form.deliveryOrder.rider.mobile}}
						<view class="f12 c9 ml10" @click.stop="tocenter(form.deliveryOrder.rider.mobile)"
							v-if="form.deliveryOrder.rider.mobile"><u-icon name="phone-fill" color="#000"
								size="20"></u-icon></view>
					</view>
				</view>
				<view class="dfbc f12 mb10" v-if="form.deliveryOrder.stateFormat">
					<text class="">配送状态</text>
					<text class="c0">{{form.deliveryOrder.stateFormat}}</text>
				</view>
			</view> -->
			<view class="card mt10 f12" style="font-size:30rpx;color:#999">
				<view class="mb10 wei6 c0">订单信息</view>
				<view class="dfbc p-5-0 f12 c0">
					<text>订单类型</text>
					<text>点单</text>
				</view>
				<!-- <view class="dfbc p-5-0 f12 c0" v-if="form.appointmentFormat">
					<text>取单类型</text>
					<text>{{ form.appointmentFormat }}</text>
				</view> -->
				<!-- <view class="dfbc p-5-0 f12 c0" v-if="form.appointment == 1 && form.serverTime">
					<text>{{form.scene==2 ? '预约自取时间':'预约送达时间'}}</text>
					<text>{{ form.serverTime }}</text>
				</view> -->
				<view class="dfbc p-5-0 f12 c0">
					<text>下单时间</text>
					<text>{{ form.create_date }}</text>
				</view>
				<view class="dfbc p-5-0 f12 c0">
					<text>订单编号</text>
					<view>
						<text>{{ form.order_no }}</text>
						<text :style="{background:subColor}" class="ml5 c0 fz" @click="fz(form.order_no)">复制</text>
					</view>
				</view>
				<!-- <view class="dfbc p-5-0 f12 c0">
					<text>商家备注</text>
					<text>
						{{ form.storeNotes || '-' }}
						<text class="ml5 c0 fz" :style="{background:subColor}" @click="editNotes(form)">编辑</text>
					</text>
				</view>
				<view class="dfbc p-5-0 f12 c0">
					<text>下单人信息</text>
					<view v-if="form.user" @click="tocenter(form.user.mobile)">
						<view class="c0">{{form.user.nickname}}<text class="ml5 c9">(ID:{{form.user.id}})</text></view>
						<view class="c9 f-x-e">{{form.user.mobile}}</view>
					</view>
				</view> -->
			</view>
			<!-- <view class="card mt10" v-if="form.log">
				<view v-for="(v,i) in form.log" :key="i" :style="{color:i===0?subColor:'#999'}">
					<view class="dfa">
						<view style="width:15rpx;height:15rpx;border-radius: 50%;"
							:style="{background:i===0?subColor:'#999'}">
						</view>
						<text class="f14 ml10">{{v.created_at}}</text>
					</view>
					<view class="f-s">
						<view style="width:2rpx;height:80rpx;margin-left: 6rpx;"
							:style="{background:i===0?subColor:'#999'}"></view>
						<text class="mt5 f14 ml10" :class="i==form.log.length-1?'pl10':''">{{v.log}}</text>
					</view>
				</view>
			</view> -->
		</view>
		<view class="buts dfa tac o-h" v-if="form.state>0 && form.state<=7" :style="{borderColor:subColor}">
			<view class="w100 f16 c0 p10 bf p-r" v-if="form.state!=7 && form.state!=2" @click.stop="outShow = !outShow">
				打印订单</view>
			<view class="w100 f16 c0 p10" @click="handOrder('refunding')" v-if="form.state==7"
				:style="{background:subColor}">同意退款</view>
			<view class="w100 f16 c0 p10 bf" @click="handOrder('refusal')" v-if="form.state==2">拒单</view>
			<view class="w100 f16 c0 p10 bf" @click="handOrder('canceling')" v-if="form.state==1">取消订单</view>
			<view class="w100 f16 c0 p10" @click="handOrder('receiving')" v-if="form.state==2"
				:style="{background:subColor}">立即接单</view>
			<view class="w100 f16 c0 p10" @click="handOrder('maked')" v-if="form.state==3"
				:style="{background:subColor}">制作完成</view>
			<view class="w100 f16 c0 p10" @click="handOrder('completeing')" v-if="form.scene != 1 && form.state == 4"
				:style="{background:subColor}">确认取单</view>
			<view class="w100 f16 c0 p10" @click="handOrder('comDelivery')" v-if="form.scene == 1 && form.state == 4"
				:style="{background:subColor}">发起配送</view>
			<view class="w100 f16 c0 p10" @click="handOrder('completeOrder')"
				v-if="form.scene == 1 && form.state == 5 && form.deliveryOrder && form.deliveryOrder.deliveryType==2"
				:style="{background:subColor}">
				确认送达</view>
			<view class="w100 f16 c0 p10" @click="handOrder('refundOrder')" v-if="form.state == 6"
				:style="{background:subColor}">退款</view>
			<view class="w100 f16 c0 p10" @click="handOrder('rejecting')" v-if="form.state == 7"
				:style="{background:'#fff'}">拒绝退款</view>
		</view>
		<view class="dayin p10 bf f14" v-if="outShow">
			<view class="item pb10" @click="handOrder('orderPrint',15)">商家联</view>
			<view class="item pb10 pt10" @click="handOrder('orderPrint',16)">顾客联</view>
			<view class="item pb10 pt10" @click="handOrder('orderPrint',17)">制作总单</view>
			<view class="item pt10 ib" @click="handOrder('orderPrint',18)">制作分单</view>
		</view>
		<!-- <u-action-sheet :actions="moreList" @select="selectClick" :closeOnClickOverlay="true" @close="moreShow = false"
			:show="moreShow" cancelText='取消'></u-action-sheet> -->
		<!-- 弹框 -->
		<u-modal :show="show" :showCancelButton="true" :closeOnClickOverlay="true" :negativeTop="30" title="商家备注"
			cancelText="取消" :confirmColor="subColor" @cancel="show=false" @close="show=false" @confirm="reasonConfirm">
			<view class="slot-content f-1">
				<u--textarea v-model="reason" placeholder="请输入备注信息"></u--textarea>
			</view>
		</u-modal>
		<u-popup :show="fqps" :safeAreaInsetBottom="false" round="10" @close="fqps=false" @open="fqps=true"
			mode="center">
			<view class="psw">
				<view class="flex p-10-0">
					<view class="f-g-0">配送地址</view>
					<view class="ml10 mr15" v-if="rows.address">
						<view class="wei">
							{{ rows.address.address }} {{ rows.address.description }}
						</view>
						<view class="mt5 f12">
							{{ rows.address.contact }}（{{ rows.address.call }}）{{
					              rows.address.mobile
					            }}
						</view>
					</view>
				</view>
				<view class="flex p-10-0">
					<view class="f-g-0">配送方式</view>
					<view class="ml10 mr15 f-g-1">
						<u-radio-group v-model="psform.deliveryType" @change="changeType" placement="column"
							iconColor="#000" labelSize='14'>
							<view class="mb5" v-if="rows.deliveryStoreRule && rows.deliveryStoreRule.deliveryType==1">
								<u-radio :activeColor="subColor" label="平台配送" :name="1"></u-radio>
							</view>
							<view class="mb5"><u-radio :activeColor="subColor" label="门店自配送" :name="2"></u-radio></view>
						</u-radio-group>
					</view>
				</view>
				<view class="flex p-10-0">
					<view class="f-g-0">配送渠道</view>
					<view class="ml10 mr15 f-g-1">
						<u-radio-group v-model="psform.channel" placement="column" labelSize='14' iconColor="#000">
							<view class="mb5" v-if="psform.deliveryType == 2">
								<u-radio :activeColor="subColor" label="商家自配送" :name="0"></u-radio>
							</view>
							<view class="mb5"
								v-if="fhChannel.includes(1) && (rows.deliveryStoreRule && rows.deliveryStoreRule.deliveryType==2 || psform.deliveryType==1)">
								<u-radio :activeColor="subColor" :label="mytName" :name="1"></u-radio>
							</view>
							<view class="mb5"
								v-if="fhChannel.includes(2) && (rows.deliveryStoreRule && rows.deliveryStoreRule.deliveryType==2 || psform.deliveryType==1)">
								<u-radio :activeColor="subColor" :label="mKName" :name="2"></u-radio>
							</view>
							<view class="mb5" v-if="psform.deliveryType == 2 && fhChannel.includes(3)"><u-radio
									:activeColor="subColor" :label="wsbName" :name="3"></u-radio>
							</view>
						</u-radio-group>
					</view>
				</view>
				<view class="mt20">
					<u-button type="primary" text="确定" :color="subColor" customStyle="color:'#000'"
						@click="save"></u-button>
				</view>
			</view>
		</u-popup>
		<u-popup :show="showPay" :round="10" @close="showPay=false" @open="showPay=true">
			<view class="p15 c0 f16">
				<view class="dfbc mb10">
					<text>支付金额</text>
					<text class="f14 " :style="{color:subColor}">￥{{form.money}}</text>
				</view>
				<view class="dfbc bb1 p-10-0">
					<u-radio-group v-model="pay.payChannel" placement='column' iconPlacement='right'
						@change="changePay">
						<u-radio :activeColor="subColor" name="authCode" :labelSize="18" :iconSize="14"
							:customStyle="{marginBottom: '50rpx'}">付款码支付</u-radio>
						<u-radio :activeColor="subColor" name="balance" :labelSize="18" :iconSize="14"
							:customStyle="{marginBottom: '50rpx'}">
							<text v-if="payVip && payVip.id">余额支付<text class="f12 c9 ml10"
									:style="{color: subColor}">{{(`余额:${payVip.account.balance}`)}}</text></text>
							<text v-else>余额支付</text>
						</u-radio>
						<u-radio :activeColor="subColor" name="cash" :labelSize="18" :iconSize="14"
							:customStyle="{marginBottom: '50rpx'}">现金支付</u-radio>
					</u-radio-group>
				</view>
				<view>
					<u-button text="立即支付" :color="subColor" @click="goPay"
						:disabled="!pay.payChannel || (pay.payChannel == 'authCode' && !pay.authCode || pay.payChannel == 'balance' && !payVip.id)">
					</u-button>
				</view>
			</view>
		</u-popup>

		<u-modal :show="vipUser" :negativeTop="200" title="会员查询" confirmText="查询" showCancelButton
			:confirmColor="subColor" cancelColor="#000" @confirm="search" @cancel="vipUser = false"
			@close="vipUser = false" :closeOnClickOverlay="true" zoom>
			<view class="slot-content">
				<u--input v-model="phone" type="number" placeholderClass="inni" placeholderStyle="color:#c1c1c1"
					placeholder="请输入手机号" border="none"
					:customStyle="{'width':'100%','flex':1,'background': '#f6f6f6','padding': '10px 15px',}" clearable>
				</u--input>
			</view>
		</u-modal>
	</view>
</template>

<script>
	import site from '@/custom/siteroot.js';
	import {
		mapState,
	} from 'vuex'
	import {
		fuzhi,
		callTel,
	} from "@/common/handutil.js";
	export default {
		data() {
			return {
				subColor: uni.getStorageSync('subject_color'),
				show: false,
				num: 0,
				src: '',
				goods: [],
				form: {},
				reason: '',
				fqps: false,
				psform: {
					deliveryType: 1,
					channel: 1,
				},
				storeInfo: {},
				rows: {},
				mytName: "麦芽田聚合配送",
				mKName: "码科配送",
				wsbName: "外送帮",
				fhChannel: [],
				type: '',
				showPay: false,
				payVip: {},
				vipUser: false,
				phone: '',
				pay: {
					payChannel: 0,
					authCode: 0,
					payUserId: 0,
					costomPayId: 0,
				},
				moreShow: false,
				id: '',
				outShow: false,
				options_status: {

					'0': {
						value: 0,
						label: '全部',
					},
					'1': {
						value: 1,
						label: '交易完成',
					},
					'10': {
						value: 10,
						label: '订单已创建',
					},
					'20': {
						value: 20,
						label: '已支付',
					},
					'30': {
						value: 30,
						label: '待接单',
					},
					'40': {
						value: 40,
						label: '已接单',
					},
					'50': {
						value: 50,
						label: '备餐中',
					},
					'51': {
						value: 51,
						label: '已出餐',
					},
					'52': {
						value: 52,
						label: '已取餐',
					},
					'101': {
						value: 101,
						label: '交易关闭',
					},
				},
			}
		},
		computed: {
			...mapState({
				storeId: state => state.storeId,
			}),
		},
		onLoad(options) {
			if (options && options.id) {
				this.id = options.id
				this.type = options.type
				this.fetchData(options.id)
			}
		},
		onShow() {
			if (this.id) {
				this.fetchData(this.id)
			}
		},
		methods: {
			async fetchData(id) {
				let {
					code,
					data,
					msg
				} = await this.beg.request({
					url: `/admin/order.Place/getOrderInfo`,
					data: {
						id: id
					},
				})
				if (code == 1) {

					data.sku.forEach((vv) => {
						vv.add_info = JSON.parse(vv.add_info);
						vv.product_info = JSON.parse(vv.product_info);
						vv.product_info.img = site.siteroot + vv.product_info.img;
						vv.sku_info = JSON.parse(vv.sku_info);
						vv.sku_name_info = JSON.parse(vv.sku_name_info);
						vv.sku_spec = JSON.parse(vv.sku_spec);
					})
					data.status_name = this.options_status[data.status].label;
					this.form = data
					console.log(data)
				} else {
					uni.$u.toast(msg)
				}

			},
			editNotes(v) {
				if (v.storeNotes && v.storeNotes != null) this.reason = v.storeNotes
				this.show = true
			},
			async reasonConfirm() {
				let {
					msg
				} = await this.beg.request({
					url: `${this.api.oNotes}/${this.form.id}`,
					method: "POST",
					data: {
						notes: this.reason
					},
				})
				this.fetchData(this.form.id)
				uni.$u.toast(msg)
				this.show = false
			},
			async handOrder(type, scene) {
				if (type == 'comDelivery') {
					this.open(this.form)
					return
				} else if (type == 'refusal') {
					uni.showModal({
						title: '取消订单',
						content: '请谨慎操作，建议提前与客户沟通达成一致！',
						cancelText: '再考虑下',
						confirmText: '确认取消',
						success: async (res) => {
							if (res.confirm) {
								return uni.navigateTo({
									url: `/pages/order/refusal?id=${this.form.id}&scene=${this.form.scene}&storeId=${this.form.storeId}&type=${this.type}`
								})
							}
						}
					})
					return
				} else if (type == 'orderPrint') {
					let {
						msg
					} = await this.beg.request({
						url: `${this.api.printOrder}/${this.form.id}`,
						method: "POST",
						data: {
							scene,
						}
					})
					this.fetchData(this.form.id)
					uni.$u.toast(msg)
					return
				}
				let n = '',
					a = ''
				switch (type) {
					// case 'orderPrint':
					// 	n = "你确定打印该订单吗";
					// 	a = 'printOrder';
					// 	break;
					case 'canceling':
						n = "你确定取消订单吗";
						a = 'oClose';
						break;
					case 'refusal':
						n = "你确定拒单吗";
						a = 'refund';
						break;
					case 'receiving':
						n = "你确定立即接单吗";
						a = 'received';
						break;
					case 'refunding':
						n = "你确定同意退款吗";
						a = 'refund';
						break
					case 'refundOrder':
						n = "你确定退款吗";
						a = 'refund';
						break
					case 'maked':
						n = "你确定制作完成吗";
						a = 'maked';
						break;
					case 'completeOrder':
						n = "你确定完成订单吗";
						a = 'complete';
						break;
					case 'completeing':
						n = "你确定确认取单吗";
						a = 'complete';
						break;
					case 'rejecting':
						n = "你确定拒绝退款吗";
						a = 'reject';
						break;
				}
				console.log(a, n)
				if (a == 'received' || a == 'maked' || a == 'completeOrder') {
					let {
						msg
					} = await this.beg.request({
						url: `${this.api[a]}/${this.form.id}`,
						method: "POST",
					})
					this.fetchData(this.form.id)
					uni.$u.toast(msg)
				} else {
					uni.showModal({
						title: '温馨提示',
						content: n,
						success: async (res) => {
							if (res.confirm) {
								let {
									msg
								} = await this.beg.request({
									url: `${this.api[a]}/${this.form.id}`,
									method: "POST",
								})
								this.fetchData(this.form.id)
								uni.$u.toast(msg)
							}
						}
					});
				}
			},
			async open(row) {
				let {
					deliverySetting
				} = uni.getStorageSync('setInfo')
				this.mytName = deliverySetting.appId || "麦芽田聚合配送";
				this.mKName = deliverySetting.appId2 || "码科配送";
				this.wsbName = deliverySetting.wsbName || "外送帮";
				let info = uni.getStorageSync('storeInfo')
				if (info) {
					this.storeInfo = info;
				}
				if (row.deliveryStoreRule.channel.includes(1)) {
					this.psform.channel = 1;
				} else if (row.deliveryStoreRule.channel.includes(2)) {
					this.psform.channel = 2;
				} else if (row.deliveryStoreRule.channel.includes(3)) {
					this.psform.channel = 3;
				} else {
					this.psform.channel = null;
				}
				this.psform.deliveryType = row.deliveryType
				this.fhChannel = row.deliveryStoreRule && row.deliveryStoreRule.channel
				this.rows = row;
				this.fqps = true;
			},
			changeType(val) {
				if (val == 2) {
					this.psform.channel = 0;
				} else {
					if (this.rows.deliveryStoreRule.channel.includes(1)) {
						this.psform.channel = 1;
					} else if (this.rows.deliveryStoreRule.channel.includes(2)) {
						this.psform.channel = 2;
					} else if (this.rows.deliveryStoreRule.channel.includes(3)) {
						this.psform.channel = 3;
					} else {
						this.psform.channel = null;
					}
				}
			},
			async save() {
				if (!this.psform.channel && String(this.psform.channel) !== '0') {
					return uni.$u.toast('请选择配送渠道')
				}
				let {
					msg
				} = await this.beg.request({
					url: `${this.api.delivery}/${this.rows.id}`,
					method: "POST",
					data: this.psform,
				})
				this.fetchData(this.form.id)
				uni.$u.toast(msg)
				this.fqps = false
			},
			torefund() {
				uni.navigateTo({
					url: `/pages/order/refund?id=${this.form.id}&money=${this.form.money}&storeId=${this.form.storeId}&type=${this.type}`
				})
			},
			fz(n) {
				fuzhi(n)
			},
			call(e) {
				callTel(e)
			},
			changePay(e) {
				if (e == 'authCode') {
					var that = this
					uni.scanCode({
						onlyFromCamera: true,
						success: async function(res) {
							uni.showLoading({
								title: 'loading...'
							})
							if (res.result) {
								that.pay.authCode = res.result
								that.goPay()
							} else {
								uni.hideLoading()
							}
						},
					});
				} else if (e == 'balance') {
					this.vipUser = true
				} else if (e == 'cash') {
					this.pay.payChannel = 'cash'
				} else {
					this.pay.costomPayId = e
					this.pay.payType = 'costomPay'
				}
			},
			async goPay() {
				let {
					data,
					msg
				} = await this.beg.request({
					url: `${this.api.inPay}/${this.form.orderSn}`,
					method: 'POST',
					data: this.pay
				})
				uni.showToast({
					title: msg,
					icon: 'none',
				});
				this.fetchData(this.form.orderSn)
				this.showPay = false
			},
			async search() {
				const reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
				if (this.phone !== "" && reg_tel.test(this.phone)) {
					this.vipUser = false
					uni.showLoading({
						title: 'loading...'
					})
					let {
						data
					} = await this.beg.request({
						url: this.api.cMember,
						data: {
							keyword: this.phone
						},
					})
					if (data && data.list.length && data.list[0].id) {
						this.payVip = data.list[0]
						this.pay.payUserId = data.list[0].id
						console.log(this.payVip)
					} else {
						uni.$u.toast('暂未查到用户信息');
					}
					uni.hideLoading()
				} else {
					uni.$u.toast('请输入正确的手机号');
				}
			},
			selectClick(val) {
				console.log(val)
			},
			tocenter(e) {
				uni.makePhoneCall({
					phoneNumber: e
				});
			},
			onPreviewTap(i) {
				let ci = []
				ci.push(i)
				uni.previewImage({
					current: 0,
					urls: ci
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.index {
		padding-bottom: 160rpx;
		overflow: auto;

		.top {
			width: 100%;
			height: 200px;
			color: #000;
		}

		.buts {
			// background: 'linear-gradient(to right, #fff 50%,'+ subColor+' 50%)'
			position: fixed;
			bottom: 40rpx;
			left: 50%;
			transform: translateX(-50%);
			width: 90%;
			height: 80rpx;
			border-radius: 50rpx;
			border: 2rpx solid #fff;
		}
	}

	.psw {
		padding: 30rpx;
		font-size: 28rpx;
		width: 650rpx;
	}

	.fz {
		padding: 6rpx;
		border-radius: 4rpx;
	}

	.bz {
		background: #FFFBE0;
		padding: 20rpx 10rpx;

		.left {
			padding: 4rpx 8rpx;
			color: #fff;
			background: linear-gradient(to right, #F6AD6D, #F95D40);
		}
	}

	.mumber {
		width: 100rpx;
	}

	.bt1 {
		border-top: 3rpx dotted #e5e5e5;
	}

	.toolPop {
		display: flex;
		flex-direction: row;
		justify-content: center;
		flex-shrink: 0;
		flex-grow: 0;
		flex-basis: auto;
		align-items: stretch;
		align-content: flex-start;
		position: absolute;
		top: 16px;
		left: -106px;
		width: 300rpx;

		.bg {
			flex-shrink: 0;
			flex-grow: 0;
			flex-basis: auto;
			background-color: #060607;
			position: relative;
			flex: 1;
			border-radius: 5px;
			padding: 0px 0;
			display: flex;
			flex-direction: row;
			align-items: center;
			overflow: hidden;
			padding: 11px 13px;
		}
	}

	.dayin {
		position: fixed;
		bottom: 125rpx;
		left: 32%;
		transform: translateX(-50%);
		width: 50%;
		box-shadow: 0px 0px 10px 0px #e6e6e6;

		.item {
			border-bottom: 1px solid #e6e6e6;
			cursor: pointer;
		}

		.ib {
			border-bottom: none;
		}
	}
</style>